package com.ss.android.wenda.c;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bytedance.article.common.c.TTUtils;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.article.common.ThumbGridLayout;
import com.ss.android.article.common.ThumbPreviewActivity;
import com.ss.android.article.common.g.ImageMeasure;
import com.ss.android.image.Image;
import com.ss.android.wenda.a.i;
import com.ss.android.wenda.model.Question;

import java.util.Collection;

public final class p extends com.ss.android.k.c.b implements View.OnClickListener {
    final class a {
        View a;
        NightModeAsyncImageView b;
        View c;
        View d;

        a(View arg2) {

            this.a = arg2;
            this.b = arg2.findViewById(com.ss.android.article.browser.R.id.image);
            this.c = arg2.findViewById(com.ss.android.article.browser.R.id.abp);
            this.d = arg2.findViewById(com.ss.android.article.browser.R.id.abq);
        }
    }

    private Question c;

    public p() {

    }

    public final View a(ViewGroup arg3) {
        View v0 = android.support.design.a.b(arg3, R.layout.it);
        a v1 = new a(v0);
        v0.setTag(v1);
        return v1.a;
    }

    public final void a(View arg7, int arg8, Object arg9) {
        int v2;
        int v4 = View.GONE;
        Object v0 = arg7.getTag();
        Object v1 = ((Question)arg9).mQuestionDesc.mThumbImages.get(arg8);
        if(((Image)v1).isLocal()) {
            v2 = ((ThumbGridLayout)this.a()).getChildWidth();
            ((a)v0).b.a(((Image)v1), v2, v2);
        }
        else {
            ((a)v0).b.setImage(((Image)v1));
        }

        ((a)v0).b.setImage(((Image)v1));
        ((a)v0).b.setTag(Integer.valueOf(arg8));
        ((a)v0).b.setOnClickListener(((View.OnClickListener)this));
        NightModeAsyncImageView v2_1 = ((a)v0).b;
        AppData.getInstance();
        if(AppData.isNightMode()) {
            ((ImageView)v2_1).setColorFilter(TTUtils.getNightModeColorFilter());
        }
        else {
            ((ImageView)v2_1).setColorFilter(null);
        }

        View v5 = ((a)v0).c;
        v2 = ((Image)v1).isGif() ? 0 : v4;
        v5.setVisibility(v2);
        float v1_1 = ImageMeasure.computeRatio(new ImageMeasure.Spec(((Image)v1).width, ((Image)v1).height));
        if(v1_1 < 0.333333f || v1_1 > 3f) {
            ((a)v0).d.setVisibility(View.VISIBLE);
        }
        else {
            ((a)v0).d.setVisibility(v4);
        }
    }

    public final void a(Object arg5) {
        if((arg5 instanceof Question)) {
            Object v0 = arg5;
            if(((Question)v0).mQuestionDesc != null && !android.support.design.a.isEmptyCollection((Collection) ((Question)v0).mQuestionDesc.mThumbImages)) {
                this.c = ((Question)v0);
                if(!android.support.design.a.isEmptyCollection((Collection) ((Question)v0).mQuestionDesc.mThumbImages) && (i.a().b().booleanValue())) {
                    this.c().d(0);
                }

                super.a(arg5);
                if(((Question)v0).mQuestionDesc.mThumbImages.size() == 1) {
                    v0 = ((Question)v0).mQuestionDesc.mThumbImages.get(0);
                    ((ThumbGridLayout) this.a()).setSingleImageUiType(2);
                    ((ThumbGridLayout)this.a()).setSingleSize(((Image)v0).width, ((Image)v0).height);
                    return;
                }

                ((ThumbGridLayout)this.a()).setItemHeight(-1);
                return;
            }

            this.c().d(8);
        }
    }

    public final int b(Object arg2) {
        int v0 = ((Question)arg2).mQuestionDesc == null || (android.support.design.a.isEmptyCollection((Collection) ((Question)arg2).mQuestionDesc.mThumbImages)) ? 0 : ((Question)arg2).mQuestionDesc.mThumbImages.size();
        return v0;
    }

    public final void onClick(View arg4) {
        ThumbPreviewActivity.startActivity(((ImageView)arg4), this.c.mQuestionDesc.mThumbImages, this.c.mQuestionDesc.mLargeImages, ((Integer)arg4.getTag()).intValue());
    }
}

